package com.zsk.shop.common.constant;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yuwenbo
 * @date 2019/4/11 13:58
 */
@Configuration
public class StaticConfigUtil {

    @Autowired
    public static MyProperties myProperties;

    @Value("${spring.active}")
    private String env;
    @Value("${spring.active-url}")
    private String url;
    @Value("${spring.active-port}")
    private String port;

    @Bean
    public void init() {
        myProperties = new MyProperties();
        myProperties.setEnv(this.env);
        myProperties.setUrl(this.url);
        myProperties.setPort(this.port);
    }

    public static String getEnv() {
        if (myProperties == null) {
            return "";
        }
        return myProperties.getEnv();
    }

    public static String getUrl() {
        if (myProperties == null) {
            return "";
        }
        return myProperties.getUrl();
    }

    public static String getPort() {
        if (myProperties == null) {
            return "";
        }
        return myProperties.getPort();
    }

}
